#ifndef __MISSING_H_INCLUDE__
#define __MISSING_H_INCLUDE__

#include <sysdep.h>

#define usleep(x)	Sleep(x)

#define PROT_READ	0x1		/* Page can be read.  */
#define PROT_WRITE	0x2		/* Page can be written.  */
#define PROT_EXEC	0x4		/* Page can be executed.  */
#define PROT_NONE	0x0		/* Page can not be accessed.  */
#define PROT_GROWSDOWN	0x01000000	/* Extend change to start of
					   growsdown vma (mprotect only).  */
#define PROT_GROWSUP	0x02000000	/* Extend change to start of
					   growsup vma (mprotect only).  */

/* Sharing types (must choose one and only one of these).  */
#define MAP_SHARED	0x01		/* Share changes.  */
#define MAP_PRIVATE	0x02		/* Changes are private.  */
#define MAP_TYPE	0x0f		/* Mask for type of mapping.  */

/* Other flags.  */
#define MAP_FIXED	0x10		/* Interpret addr exactly.  */
#define MAP_FILE	0
#define MAP_ANONYMOUS	0x20		/* Don't use a file.  */
#define MAP_ANON	MAP_ANONYMOUS

/* Flags to `msync'.  */
#define MS_ASYNC	1		/* Sync memory asynchronously.  */
#define MS_SYNC		4		/* Synchronous memory sync.  */
#define MS_INVALIDATE	2		/* Invalidate the caches.  */

/* Flags for `mlockall'.  */
#define MCL_CURRENT	1		/* Lock all currently mapped pages.  */
#define MCL_FUTURE	2		/* Lock all additions to address

/* Return value of `mmap' in case of an error.  */
#define MAP_FAILED	((void *) -1)

ssize_t readlink(const char *path, char *buf, size_t len);

int mount(const char *specialfile, const char *dir,
	  const char *filesystemtype, unsigned long rwflag,
	  const void *data);
int symlink(const char *oldpath, const char *newpath);
void *mmap(void *addr, size_t len, int prot,
	   int flags, int fd, off_t offset);
int munmap(void *buf, size_t bufsize);
int msync(void *addr, size_t len, int flags);

void unsetenv(const char *name);
int setenv(const char *name, const char *value, int overwrite);

static unsigned int gnu_dev_major(uint64_t __dev)
{
	return (uint32_t)((__dev >> 8) & 0xfff) | ((unsigned int) (__dev >> 32) & ~0xfff);
}

static unsigned int gnu_dev_minor(uint64_t __dev)
{
	return (uint32_t)(__dev & 0xff) | ((unsigned int) (__dev >> 12) & ~0xff);
}

static uint64_t gnu_dev_makedev(unsigned int __major, unsigned int __minor)
{
	return ((__minor & 0xff) | ((__major & 0xfff) << 8) |
		(((uint64_t) (__minor & ~0xff)) << 12) |
		(((uint64_t) (__major & ~0xfff)) << 32));
}

/* Access the functions with their traditional names.  */
# define major(dev) gnu_dev_major(dev)
# define minor(dev) gnu_dev_minor(dev)
# define makedev(maj, min) (dev_t)gnu_dev_makedev(maj, min)

/* File listing canonical interesting mount points.  */
#define	MNTTAB		"/dev/mtab"	/* Deprecated alias.  */

/* File listing currently active mount points.  */
#define	MOUNTED		"/etc/mtab"	/* Deprecated alias.  */


/* General filesystem types.  */
#define MNTTYPE_IGNORE	"ignore"	/* Ignore this entry.  */
#define MNTTYPE_NFS	"nfs"		/* Network file system.  */
#define MNTTYPE_SWAP	"swap"		/* Swap device.  */


/* Generic mount options.  */
#define MNTOPT_DEFAULTS	"defaults"	/* Use all default options.  */
#define MNTOPT_RO	"ro"		/* Read only.  */
#define MNTOPT_RW	"rw"		/* Read/write.  */
#define MNTOPT_SUID	"suid"		/* Set uid allowed.  */
#define MNTOPT_NOSUID	"nosuid"	/* No set uid allowed.  */
#define MNTOPT_NOAUTO	"noauto"	/* Do not auto mount.  */

/* Structure describing a mount table entry.  */
struct mntent {
	char *mnt_fsname;	/* Device or server for filesystem.  */
	char *mnt_dir;		/* Directory mounted on.  */
	char *mnt_type;		/* Type of filesystem: ufs, nfs, etc.  */
	char *mnt_opts;		/* Comma-separated options for fs.  */
	int mnt_freq;		/* Dump frequency (in days).  */
	int mnt_passno;		/* Pass number for `fsck'.  */
};


/* Prepare to begin reading and/or writing mount table entries from the
 * beginning of FILE.  MODE is as for `fopen'.
 */
extern FILE *setmntent (const char *__file, const char *__mode);

/* Read one mount table entry from STREAM.  Returns a pointer to storage
 * reused on the next call, or null for EOF or error (use feof/ferror to
 * check).
 */
extern struct mntent *getmntent(FILE *stream);

/* Write the mount table entry described by MNT to STREAM.
 * Return zero on success, nonzero on failure.
 */
extern int addmntent(FILE *stream,
		     const struct mntent *mnt);

/* Close a stream opened with `setmntent'.  */
extern int endmntent(FILE *stream);

/* Search MNT->mnt_opts for an option matching OPT.
   Returns the address of the substring, or null if none found.  */
extern char *hasmntopt(const struct mntent *mnt,
		       const char *opt);

/* Bits set in the FLAGS argument to `fnmatch'.  */ 
#define FNM_PATHNAME    (1 << 0)/* No wildcard can ever match `/'.  */ 
#define FNM_NOESCAPE    (1 << 1)/* Backslashes don't quote special chars.  */ 
#define FNM_PERIOD      (1 << 2)/* Leading `.' is matched only explicitly.  */ 
#define __FNM_FLAGS     (FNM_PATHNAME|FNM_NOESCAPE|FNM_PERIOD) 
 
/* Value returned by `fnmatch' if STRING does not match PATTERN.  */ 
#define FNM_NOMATCH     1 
 
/* Match STRING against the filename pattern PATTERN, 
   returning zero if it matches, FNM_NOMATCH if not.  */ 
int fnmatch(const char *pattern, const char *string, int flags);

#endif /* __MISSING_H_INCLUDE__ */
